import axios from "axios"
import { apiUrl } from "./domain"

const sendPost = function (path = "", data = {}) {
    return new Promise((resolve, reject) => {
        axios({
            method: "POST",
            url: apiUrl + path,
            data,
            headers: {
                token: localStorage.getItem("token") || ""
            }
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

const sendGet = function (path = "", params = {}) {
    return new Promise((resolve, reject) => {
        axios({
            method: "GET",
            url: apiUrl + path,
            params,
            headers: {
                token: localStorage.getItem("token") || ""
            }
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

export {
    sendPost,
    sendGet,
}